<template>
<div class="about">
  <h2>x: {{x}} , y: {{y}}</h2>
  <hr>
  <h2 v-if="loading">LOADING...</h2>
  <h2 v-else-if="errorMsg">{{errorMsg}}</h2>
  <img v-else-if="result" :src="result[0].url" alt="">

</div>
</template>

<script lang="ts">
import useClickPosition from '@/hooks/useClickPosition'
import useUrlLoader from '@/hooks/useUrlLoader'

interface DogResult {
  message: string;
  status: string;
}

interface CatResult {
  url: string;
  id: number
}

export default {

  setup() {
    const {x, y} = useClickPosition()
    // const {loading, result, errorMsg} = useUrlLoader<DogResult>('https://dog.ceo/api/breeds/image/random')
    const {loading, result, errorMsg} = useUrlLoader<CatResult[]>('https://api.thecatapi.com/v1/images/search')

    return {
      x,
      y,
      loading, 
      result, 
      errorMsg
    }
    
  }
}
</script>
